<?php
$question_id = $_GET['question_id'];


if ($_POST['Submit']) {
	$question_text = $_POST['question'];
	$question_type = $_POST['question_type'];
	$values = $_POST['values'];
	$required = $_POST['required'] ? 'Y':'N';
	
	$wpdb->query("UPDATE $em_question_table set `question_type` = '$question_type', `question` = '$question_text', " 
				. " `values` = '$values', `required` = '$required' where id = $question_id ");
}

$question = $wpdb->get_row("SELECT * from $em_question_table where id = '$question_id'");

if ($_POST['Submit']) {
	?>
	<div id="message" class="updated fade"><p><strong>Question saved, <a href="<?php echo EM_URL ?>edit-questions.php&amp;event_id=<?php echo $question->event_id ?>">return to question list.</a></strong></p></div>
	<?php
}
?>

<div class="wrap">
<h2>Edit Question</h2>
<h3><a href="<?php echo EM_URL ?>edit-questions.php&amp;event_id=<?php echo $question->event_id ?>">&laquo; Question List</a> </h3>
<form name="form1" method="post" action=""> 
<!-- input type="hidden" name="question_id" value="<?php echo $question->id ?>"/ -->
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="top"> 
	<th width="33%" scope="row">Question:</th> 
	<td><input name="question" type="text" id="question" size="50" value="<?php echo $question->question ?>"/></td> 
</tr>
<tr valign="top">
	<th width="33%" scope="row">Type:</th>
	<td>
		<?php $sel = ' selected="selected"'; ?>
		<select name="question_type" id="question_type" >
			<option value="TEXT"<?php echo $question->question_type == "TEXT" ? $sel : "" ?>>Text</option>
			<option value="TEXTAREA"<?php echo $question->question_type == "TEXTAREA" ? $sel : "" ?>>Text Area</option>
			<option value="SINGLE"<?php echo $question->question_type == "SINGLE" ? $sel : "" ?>>Single</option>
			<option value="MULTIPLE"<?php echo $question->question_type == "MULTIPLE" ? $sel : "" ?>>Multiple</option>
		</select>
	</td>
</tr>
<tr valign="top">
	<th width="33%" scope="row">Values:</th>
	<td><input name="values" type="text" id="values" size="50" value="<?php echo $question->values ?>"/></td>
</tr>
<tr valign="top">
	<th width="33%" scope="row">Required:</th>
	<td><input name="required" type="checkbox" id="required" <?php echo $question->required == "Y" ? 'checked="checked"':"" ?>/></td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Edit Question') ?> &raquo;" />
</p>
</form>
</div>